home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / dwyer2 / cosgen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-02  |  690 b   |  37 lines

  1. /* Listing 3        Cosine Table Generation */
  2.  
  3.  
  4. #include <math.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. /*
  9.     This is the routine used to generate the table used in the
  10.     fixed point sine and cosine functions.
  11. */
  12.  
  13.  
  14. #define PI                 3.14159265358979323846
  15. #define DEGREES_IN_CIRCLE  (1L << 12)
  16. #define TABLE_UNITY        (1L << 14)
  17.  
  18.  
  19.  
  20. int main( void )
  21. {
  22.    double degree, step;
  23.    unsigned short value;
  24.    int column;
  25.  
  26.    step = (2.0 * PI) / DEGREES_IN_CIRCLE;
  27.  
  28.    for( degree = 0.0, column = 0; degree < PI / 2.0; degree += step )
  29.    {
  30.       value = (unsigned short)(TABLE_UNITY * cos( degree ));
  31.       printf( "0x%04hx,%c", value, ++column % 8 ? ' ' : '\n' );
  32.    }
  33.  
  34.    return( 0 );
  35. }
  36.  
  37.